/** @file               sw_threadpool.h
 *  @copyright          Copyright (C) 2006-2026 flyfish (tenggui_fu@126.com)
 *  @brief              This file is part of the swallow library
 *  @author             $Author: flyfish $
 *  @version            $Rev: 385 $
 *  @date               $Date: 2016-12-22 00:12:05 +0800 (周四, 22 12月 2016) $
 */
#ifndef __SW_THREADPOOL_H__
#define __SW_THREADPOOL_H__

typedef SW_VOID *SW_THREADPOOL;
#define SW_INVALID_THREADPOOL   NULL

typedef SW_RET (*SW_THREADPOOL_TASK_PROC)(SW_VOID *pArg, SW_THREADPOOL threadPool, SW_UINT32 index, SW_UINT32 taskPrio);

#define SW_THREADPOOL_TASK_PRIO_MIN      0
#define SW_THREADPOOL_TASK_PRIO_MAX      100
#define SW_THREADPOOL_TASK_PRIO_LEVEL    (SW_THREADPOOL_TASK_PRIO_MAX - SW_THREADPOOL_TASK_PRIO_MIN) / 6
#define SW_THREADPOOL_TASK_PRIO_LOWEST   SW_THREADPOOL_TASK_PRIO_MIN
#define SW_THREADPOOL_TASK_PRIO_LOWER    (SW_THREADPOOL_TASK_PRIO_MIN + SW_THREADPOOL_TASK_PRIO_LEVEL)
#define SW_THREADPOOL_TASK_PRIO_LOW      (SW_THREADPOOL_TASK_PRIO_MIN + SW_THREADPOOL_TASK_PRIO_LEVEL * 2)
#define SW_THREADPOOL_TASK_PRIO_MID      (SW_THREADPOOL_TASK_PRIO_MIN + SW_THREADPOOL_TASK_PRIO_LEVEL * 3)
#define SW_THREADPOOL_TASK_PRIO_HIGH     (SW_THREADPOOL_TASK_PRIO_MIN + SW_THREADPOOL_TASK_PRIO_LEVEL * 4)
#define SW_THREADPOOL_TASK_PRIO_HIGHER   (SW_THREADPOOL_TASK_PRIO_MIN + SW_THREADPOOL_TASK_PRIO_LEVEL * 5)
#define SW_THREADPOOL_TASK_PRIO_HIGHEST  SW_THREADPOOL_TASK_PRIO_MAX

SW_API SW_RET SW_InitThreadPoolAPI(SW_VOID);
SW_API SW_RET SW_RunThreadPoolAPI(SW_VOID);
SW_API SW_RET SW_StopThreadPoolAPI(SW_VOID);
SW_API SW_RET SW_ExitThreadPoolAPI(SW_VOID);
SW_API SW_THREADPOOL SW_CreateThreadPool(const SW_CHAR *pPoolName, SW_UINT32 threadPrio, SW_UINT32 stackSize, SW_UINT32 threadNum, SW_UINT32 taskMax);
SW_API SW_RET SW_DeleteThreadPool(SW_THREADPOOL threadPool);
SW_API SW_RET SW_AddThreadPoolTask(SW_THREADPOOL threadPool, SW_UINT32 taskPrio, SW_THREADPOOL_TASK_PROC taskProc, SW_VOID *pArg);
SW_API SW_RET SW_TryAddThreadPoolTask(SW_THREADPOOL threadPool, SW_UINT32 taskPrio, SW_THREADPOOL_TASK_PROC taskProc, SW_VOID *pArg);
SW_API SW_RET SW_TimeAddThreadPoolTask(SW_THREADPOOL threadPool, SW_UINT32 taskPrio, SW_THREADPOOL_TASK_PROC taskProc, SW_VOID *pArg, SW_UINT32 msec);
SW_API const SW_CHAR *SW_GetThreadPoolName(SW_THREADPOOL threadPool);
SW_API SW_UINT32 SW_GetThreadPoolThreadNum(SW_THREADPOOL threadPool);
SW_API SW_UINT32 SW_GetThreadPoolAliveCount(SW_THREADPOOL threadPool);
SW_API SW_UINT32 SW_GetThreadPoolBusyCount(SW_THREADPOOL threadPool);
SW_API SW_UINT32 SW_GetThreadPoolTaskMax(SW_THREADPOOL threadPool);
SW_API SW_UINT32 SW_GetThreadPoolTaskCount(SW_THREADPOOL threadPool);
SW_API SW_RET SW_StartAsyncTask(SW_THREADPOOL_TASK_PROC taskProc, SW_VOID *pArg);
#ifndef SW_V_DISABLE_CMDSERVER
SW_API SW_RET SW_CmdThreadPoolInfo(SW_THREADPOOL threadPool);
SW_API SW_RET SW_CmdAsyncTaskInfo(SW_VOID);
#endif

#endif
